
var URL ="http://8.129.53.188:9091/"
// var URL ="http://192.168.2.68:9091/"

// 市场监管人员 农贸市场可视化页面

// var legal_person_data = {"uploadData":[{"count":630},{"count":986},{"count":792},{"count":642},{"count":521},{"count":573}
// 					,{"count":832},{"count":747},{"count":983},{"count":836},{"count":831},{"count":633}],
// 		"updateData":[{"count":110},{"count":181},{"count":123},{"count":197},{"count":123},{"count":173}
// 					,{"count":123},{"count":151},{"count":101},{"count":152},{"count":101},{"count":177}],
// 		"viewData":[{"count":651},{"count":842},{"count":223},{"count":223},{"count":221},{"count":812}
// 					,{"count":928},{"count":219},{"count":613},{"count":254},{"count":981},{"count":301}]}
// 				;
// var people_data = {"uploadData":[{"count":1300},{"count":1686},{"count":1692},{"count":1742},{"count":1621},{"count":773}
// 				,{"count":832},{"count":1047},{"count":1483},{"count":1336},{"count":831},{"count":973}],
// 	"updateData":[{"count":103},{"count":281},{"count":203},{"count":197},{"count":173},{"count":154}
// 				,{"count":223},{"count":251},{"count":201},{"count":252},{"count":201},{"count":277}],
// 	"viewData":[{"count":651},{"count":842},{"count":223},{"count":223},{"count":221},{"count":812}
// 				,{"count":928},{"count":219},{"count":613},{"count":254},{"count":981},{"count":301}]};
// var picture_data = {"uploadData":[{"count":330},{"count":786},{"count":492},{"count":842},{"count":421},{"count":673}
// 				,{"count":932},{"count":447},{"count":583},{"count":436},{"count":331},{"count":433}],
// 	"updateData":[{"count":10},{"count":81},{"count":23},{"count":97},{"count":23},{"count":73}
// 				,{"count":23},{"count":51},{"count":01},{"count":52},{"count":01},{"count":77}],
// 	"viewData":[{"count":451},{"count":342},{"count":523},{"count":323},{"count":421},{"count":812}
// 				,{"count":728},{"count":619},{"count":613},{"count":554},{"count":481},{"count":301}]};
			
// var Tpl1 = '<li>' +
// 			'<p class="data-count">5681</p>' +
// 			'<span class="data-name">数据总量</span>' +
// 			'</li>' +
// 			'<li>' +
// 			'<p class="data-count">1331</p>' +
// 			'<span class="data-name">更新量</span>' +
// 			'</li>' +
// 			'<li>' +
// 			'<p class="data-count">3753</p>' +
// 			'<span class="data-name">共享次数</span>' +
// 			'</li>' ;		
// var Tpl2 = '<li>' +
// 			'<p class="data-count">3971</p>' +
// 			'<span class="data-name">数据总量</span>' +
// 			'</li>' +
// 			'<li>' +
// 			'<p class="data-count">1141</p>' +
// 			'<span class="data-name">更新量</span>' +
// 			'</li>' +
// 			'<li>' +
// 			'<p class="data-count">3753</p>' +
// 			'<span class="data-name">共享次数</span>' +
// 			'</li>' ;
// var Tpl3 = '<li>' +
// 			'<p class="data-count">4742</p>' +
// 			'<span class="data-name">数据总量</span>' +
// 			'</li>' +
// 			'<li>' +
// 			'<p class="data-count">1231</p>' +
// 			'<span class="data-name">更新量</span>' +
// 			'</li>' +
// 			'<li>' +
// 			'<p class="data-count">2983</p>' +
// 			'<span class="data-name">共享次数</span>' +
// 			'</li>' ;		
// $('.com-screen-content .use-data').html(Tpl1);			
// 基于准备好的dom，初始化echarts实例
var myChart1= echarts.init(document.getElementById('main1'));
var myChart2 = echarts.init(document.getElementById('main2'));
var myChart3 = echarts.init(document.getElementById('main3'));
//var myChart4 = echarts.init(document.getElementById('main4'));
// var myChart5 = echarts.init(document.getElementById('main5'));

// 各市场今日贴标量
var myChart6 = echarts.init(document.getElementById('main6'));
var myChart7 = echarts.init(document.getElementById('main7'));


getNowFormatDate();
getDeadlineNow();
getUsers();
marketAjax();
// allLabelAjax();
charts2Ajax();
charts6Ajax();
charts7Ajax();



$('.select').on('blur', function () {
	$(this).find('.select-ul').hide();
})
//下拉框点击出现下拉框内容
$('.select-div').on('click', function () {
if ($(this).siblings('.select-ul').is(":hidden")) {
	$(this).siblings('.select-ul').show();
} else {
	$(this).siblings('.select-ul').hide();
}
})


$('.select-ul').on('click', 'li', function () {
$(this).addClass('active').siblings('li').removeClass('active').parent().hide().siblings('.select-div').html($(this).html());
var parentDiv = $(this).parent().parent().parent();
})

// 获取所有父类下的数据
function getDeadlineNow() {
    $.ajax({
        type: "GET",
        // url: `${URL}PoultrySales/findCountOfParentThisYear/by/house?houseId=${marketId}`,
        url:`${URL}supervise/allpoultrynum`,
        dataType: "json",
        success(data) {
            data = data.object
			init_myChart1(data)
            deadlineNow(data)
        },
        error() { }
    })
}

// 迄今为止
function deadlineNow(data) {
    let allDeadline = ''
	for (var i = 0; i < data.length; i++) {
		allDeadline +=
			'<ul class="use-data">'+
			'<li>' +
				'<p class="data-name">' + data[i].name + '</p>' +
			'</li>'	+
			'<li>' +
				'<p class="data-count">' + data[i].value + '</p>' +
			'</li>'+
			'</ul>'
		$(".deadlineNow").html(allDeadline)
	}
}

// 禽类贴标占比
function init_myChart1(data){
	option = {
			tooltip : {
				trigger: 'item',
				formatter: "{b} : {c} ({d}%)"
			},
			color:['#8fc31f','#f35833','#00ccff','#ffcc00','#f5e965','#a74faf','#ff9668'],
		   
			series : [
				{
					// name: '资源总量构成',
					type: 'pie',
					radius : '45%',
					center: ['50%', '50%'],
					// data:[
					// 	{value:432, name:'鸡'},
					// 	{value:679, name:'鸭'},
					// 	{value:848, name:'鹅'},
					// 	{value:848, name:'其他'}
					// ],
					data:data,
					itemStyle: {
						emphasis: {
							shadowBlur: 10,
							shadowOffsetX: 0,
							shadowColor: 'rgba(0, 0, 0, 0.5)'
						}
					},
					itemStyle: {
						normal: {
							label:{ 
								show: true, 
	//	                            position:'inside',
								formatter: '{b} : {c} ({d}%)' ,
								fontSize : 14,    //文字的字体大小
							}
						},
						labelLine :{show:true}
					}
				}
			]
		};
// 使用刚指定的配置项和数据显示图表。
	myChart1.setOption(option);
}

var charts2Data = null;
//某镇总体贴标数据ajax
function charts2Ajax() {
    $.ajax({
        type: 'GET',
        // url: `${URL}supervise/findnumByMarketToday/houseId?id=${marketId}`,
        url:`${URL}supervise/findninenum`,
        dataType: "json",
        success: function (data) {
            charts2Data  = data.object;   
        },
        error: function (data) { }
    })
}

var num =0 ;
//  小榄镇总体超市/餐厅贴标数据
function resourceType() {
    $('.data-label li').eq(num).addClass('active').siblings().removeClass('active');
    urlType();
    num++;
    if (num >= 2) {
        num = 0;
    }
}

//   类型点击切换
$('.data-label').on('click', 'li', function () {
    $(this).addClass('active').siblings().removeClass('active');
    $('.active-data-label').html($('.data-label li.active').html());
    resourceType();
});
var oTimer = setInterval(resourceType, 7000);
//    hover清除定时器
$('.data-label').hover(function () {
    clearInterval(oTimer);
}, function () {
    oTimer = setInterval(resourceType, 7000);
});

var resourceDataType = $('.data-label li.active').data('type');//用于切换
function urlType() {
	var totalDayCount = [];
	var totalMonthCount = [];
	var totalDayTime = [];
	var totalDayTime1 = [];
	var totalMonthTime = [];
	var totalMonthTime1 = [];

	
	if (charts2Data == null) {
		return;
	}
	
	if (charts2Data.totalDay != null) {
		
		for (var i = charts2Data.totalDay.length-1; i >= 0; i--) {
			totalDayCount.push(charts2Data.totalDay[i].count);
		}
		for (var i = charts2Data.totalDay.length-1; i >= 0; i--) {
			totalDayTime1.push(charts2Data.totalDay[i].time);
		}
	}

	if (charts2Data.totalMonth != null) {
		for (var i = charts2Data.totalMonth.length-1 ; i >= 0; i--) {
			totalMonthCount.push(charts2Data.totalMonth[i].count);
		}
		for (var i = charts2Data.totalMonth.length-1 ; i >= 0; i--) {
			totalMonthTime1.push(charts2Data.totalMonth[i].time);
		}
	}

	// 对日期进行替换和加字符串处理
	totalDayTime1.forEach(e => {
		e = e + '日'
		e = e.replace(/-/,'年\n').replace(/年\n0/,'年\n').replace(/-/,'月').replace(/月0/,'月')
		totalDayTime.push(e);
	});

	// 对月份进行替换和加字符串处理
	totalMonthTime1.forEach(e => {
		e = e + '月'
		e = e.replace(/-/,'年\n').replace(/年\n0/,'年\n')
		totalMonthTime.push(e);
	});
	console.log(totalMonthTime);

    resourceDataType = $('.data-label li.active').data('type');
    if (resourceDataType == 1) {
		init_myChart2(totalDayCount,totalDayTime);
    } else if (resourceDataType == 2) {
        // init_myChart3(people_data);
		init_myChart2(totalMonthCount,totalMonthTime);
    } 
}



//某镇总体贴标数据
function init_myChart2(count,time) {
	option = {
	
		tooltip: {
			trigger: 'axis',
			formatter: function (params, ticket, callback) {
				var res = '';
				for (var i = 0, l = params.length; i < l; i++) {
					res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
				}
				return res;
			},
			transitionDuration: 0,
			backgroundColor: 'rgba(83,93,105,0.8)',
			borderColor: '#535b69',
			borderRadius: 8,
			borderWidth: 2,
			padding: [5, 10],
			axisPointer: {
				type: 'line',
				lineStyle: {
					type: 'dashed',
					color: '#ffff00'
				}
			}
		},
		legend: {
			icon: 'circle',
			itemWidth: 8,
			itemHeight: 8,
			itemGap: 10,
			top: '16',
			right: '10',
			// data: ['数据总量','共享次数','更新量'],
			textStyle: {
				fontSize: 14,
				color: '#a0a8b9'
			}
		},
		grid: {
			top:'46',
			left: '8%',
			right: '30',
			//bottom: '10%',
			containLabel: false
		},
		xAxis: [{
			type: 'category',
			boundaryGap: false,
			axisLabel: {
				interval: 0,
				fontSize:14
			},
			axisLine: {
				show: false,
				lineStyle: {
					color: '#a0a8b9'
				}
			},
			axisTick: {
				show: false
			},
			data: time,
			offset: 10
		}],
		yAxis: [{
			type: 'value',
			axisLine: {
				show: false,
				lineStyle: {
					color: '#a0a8b9'
				}
			},
			axisLabel: {
				margin: 10,
				textStyle: {
					fontSize: 14
				}
			},
			splitLine: {
				lineStyle: {
					color: '#2b3646'
				}
			},
			axisTick: {
				show: false
			}
		}],
		series: [
			{
			name: '今日贴标数',
			type: 'line',
			smooth: true,
			showSymbol: false,
			lineStyle: {
				normal: {
					width: 2
				}
			},
			areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0,
						color: 'rgba(107, 180, 28, 0.3)'
					}, {
						offset: 0.8,
						color: 'rgba(107, 180, 28, 0)'
					}], false),
					shadowColor: 'rgba(0, 0, 0, 0.1)',
					shadowBlur: 10
				}
			},
			itemStyle: {
				normal: {
					color: '#1cc840'
				}
			},
			data: count
		}, 
			// {
			// 	name: '平均贴标数',
			// 	type: 'line',
			// 	smooth: true,
			// 	showSymbol: false,
			// 	lineStyle: {
			// 		normal: {
			// 			width: 2
			// 		}
			// 	},
			// 	areaStyle: {
			// 		normal: {
			// 			color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
			// 				offset: 0,
			// 				color: 'rgba(219, 50, 51, 0.3)'
			// 			}, {
			// 				offset: 0.8,
			// 				color: 'rgba(219, 50, 51, 0)'
			// 			}], false),
			// 			shadowColor: 'rgba(0, 0, 0, 0.1)',
			// 			shadowBlur: 10
			// 		}
			// 	},
			// 	itemStyle: {
			// 		normal: {
			// 			color: '#eb5690'
			// 		}
			// 	},
			// 	data: viewCnt
			// }, 
		//  {
		// 	name: '更新量',
		// 	type: 'line',
		// 	smooth: true,
		// 	showSymbol: false,
		// 	lineStyle: {
		// 		normal: {
		// 			width: 2
		// 		}
		// 	},
		// 	areaStyle: {
		// 		normal: {
		// 			color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
		// 				offset: 0,
		// 				color: 'rgba(0, 136, 212, 0.3)'
		// 			}, {
		// 				offset: 0.8,
		// 				color: 'rgba(0, 136, 212, 0)'
		// 			}], false),
		// 			shadowColor: 'rgba(0, 0, 0, 0.1)',
		// 			shadowBlur: 10
		// 		}
		// 	},
		// 	itemStyle: {
		// 		normal: {
		// 			color: '#43bbfb'
		// 		}
		// 	},
		// 	data: updateCnt
		// }
		]
	};
	myChart2.setOption(option);
}

var marketData = null;
// 返回所有农贸市场ajax
function marketAjax() {
    $.ajax({
        type: 'GET',
        // url: `${URL}supervise/findnumByMarketToday/houseId?id=${marketId}`,
        url:`${URL}supervise/allMarket`,
        dataType: "json",
        success: function (data) {
            marketData  = data.object;      
            marketSelect(marketData);
			initMarketID = marketData.length-1;
			allLabelSelect(initMarketID,marketData);
        },
        error: function (data) { }
    })
}

// 选择农贸市场
function marketSelect(marketData){
	let allMarketSelect = ''
	for (var i = marketData.length-1 ; i >= 0; i--) {
		allMarketSelect +=
			`<li onclick="allLabelSelect(${i},marketData)">${marketData[i].name}</li>
			`
		$(".market-ul").html(allMarketSelect)
	}
}

// 选择农贸市场
function allLabelSelect(i,marketData){
	let id =  marketData[i].id;
	allLabelAjax(id);
}



// 各月贴标数ajax
function allLabelAjax(id) {
	console.log(id);
    $.ajax({
        type: 'GET',
        url:`${URL}supervise/nearpoultrynum?toMarketId=${id}`,
        dataType: "json",
        success: function (data) {
            allLabelData  = data.object;      
            init_myChart3(allLabelData);
        },
        error: function (data) { }
    })
}

// 近九月贴标数
function init_myChart3(allLabelData) {
	var duck = [];
	var goose = [];
	var fowl = [];
	var rest = [];
	var month = [];
	var month1 = allLabelData.month.reverse();
	
	// 对月份进行替换和加字符串处理
	month1.forEach(e => {
		e = e + '月'
		e = e.replace(/-/,'年\n').replace(/年\n0/,'年\n')
		month.push(e);
	});

	for (var i = allLabelData.count.duck.length-1; i >=0 ; i--) {
		duck.push(allLabelData.count.duck[i].num);
	}


	if (allLabelData.count != null) {
		for (var i = allLabelData.count.duck.length-1; i >=0 ; i--) {
			duck.push(allLabelData.count.duck[i].num);
		}
		for (var i = allLabelData.count.goose.length-1; i >=0 ; i--) {
			goose.push(allLabelData.count.goose[i].num);
		}
		for (var i = allLabelData.count.else.length-1; i >=0 ; i--) {
			rest.push(allLabelData.count.else[i].num);
		}
		for (var i = allLabelData.count.fowl.length-1; i >=0 ; i--) {
			fowl.push(allLabelData.count.fowl[i].num);
		}
	}

	
	
	option = {
		tooltip: {
			trigger: 'axis',
			formatter: function (params, ticket, callback) {
				var res = '';
				for (var i = 0, l = params.length; i < l; i++) {
					res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
				}
				return res;
			},
			transitionDuration: 0,
			backgroundColor: 'rgba(83,93,105,0.8)',
			borderColor: '#535b69',
			borderRadius: 8,
			borderWidth: 2,
			padding: [5, 10],
			axisPointer: {
				type: 'line',
				lineStyle: {
					type: 'dashed',
					color: '#ffff00'
				}
			}
		},
		legend: {
			icon: 'circle',
			itemWidth: 8,
			itemHeight: 8,
			itemGap: 10,
			top: '16',
			right: '10',
			textStyle: {
				fontSize: 14,
				color: '#a0a8b9'
			}
		},
		grid: {
			top: '46',
			left: '8%',
			right:'6%',
			// right: '10',
			//bottom: '10%',
			containLabel: false
		},
		xAxis: [{
			type: 'category',
			boundaryGap: false,
			axisLabel: {
				interval: 0,
				fontSize:14
			},
			axisLine: {
				show: false,
				lineStyle: {
					color: '#a0a8b9'
				}
			},
			axisTick: {
				show: false
			},
			data: month,
			offset: 10,
			"axisLabel": {
				"interval": 0,
				fontSize:14,
				// formatter:function(value)
				// {	

				// 	var ret = "";//拼接加\n返回的类目项
				// 	var maxLength = 4;//每项显示文字个数
				// 	var valLength = value.length;//X轴类目项的文字个数
				// 	var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
				// 	if (rowN > 1)//如果类目项的文字大于3,
				// 	{
				// 		for (var i = 0; i < rowN; i++) {
				// 			var temp = "";//每次截取的字符串
				// 			var start = i * maxLength;//开始截取的位置
				// 			var end = start + 1 + maxLength;//结束截取的位置
				// 			//这里也可以加一个是否是最后一行的判断，但是不加也没有影响，那就不加吧
				// 			temp = value.substring(start, end) + "\n";
				// 			ret += temp; //凭借最终的字符串
				// 		}
				// 		return ret;
				// 	}
				// 	else {
				// 		return value;
				// 	}
				// }
			},
		}],
		yAxis: [{
			type: 'value',
			axisLine: {
				show: false,
				lineStyle: {
					color: '#a0a8b9'
				}
			},
			axisLabel: {
				margin: 10,
				textStyle: {
					fontSize: 14
				}
			},
			splitLine: {
				lineStyle: {
					color: '#2b3646'
				}
			},
			axisTick: {
				show: false
			}
		}],
		series: [{
			name: '鸡',
			type: 'line',
			smooth: true,
			showSymbol: false,
			lineStyle: {
				normal: {
					width: 2
				}
			},
			areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0,
						color: 'rgba(137, 189, 27, 0.3)'
					}, {
						offset: 0.8,
						color: 'rgba(137, 189, 27, 0)'
					}], false),
					shadowColor: 'rgba(0, 0, 0, 0.1)',
					shadowBlur: 10
				}
			},
			itemStyle: {
				normal: {
					color: '#1cc840'
				}
			},
			data: fowl
		}, {
			name: '鸭',
			type: 'line',
			smooth: true,
			showSymbol: false,
			lineStyle: {
				normal: {
					width: 2
				}
			},
			areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0,
						color: 'rgba(219, 50, 51, 0.3)'
					}, {
						offset: 0.8,
						color: 'rgba(219, 50, 51, 0)'
					}], false),
					shadowColor: 'rgba(0, 0, 0, 0.1)',
					shadowBlur: 10
				}
			},
			itemStyle: {
				normal: {
					color: '#eb5690'
				}
			},
			data: duck
		},  {
			name: '鹅',
			type: 'line',
			smooth: true,
			showSymbol: false,
			lineStyle: {
				normal: {
					width: 2
				}
			},
			areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0,
						color: 'rgba(0, 136, 212, 0.3)'
					}, {
						offset: 0.8,
						color: 'rgba(0, 136, 212, 0)'
					}], false),
					shadowColor: 'rgba(0, 0, 0, 0.1)',
					shadowBlur: 10
				}
			},
			itemStyle: {
				normal: {
					color: '#43bbfb'
				}
			},
			data: goose
		},
		{
			name: '其他',
			type: 'line',
			smooth: true,
			showSymbol: false,
			lineStyle: {
				normal: {
					width: 2
				}
			},
			areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0,
						color: 'rgba(255, 204, 0, 0.3)'
					}, {
						offset: 0.8,
						color: 'rgba(255, 204, 0, 0)'
					}], false),
					shadowColor: 'rgba(0, 0, 0, 0.1)',
					shadowBlur: 10
				}
			},
			itemStyle: {
				normal: {
					color: '#ffcc00'
				}
			},
			data: rest
		}
		]
	};
	myChart3.setOption(option);
}


function init_myChart5(){
	var XData=["鸡","鸭","鹅","其他"];
	var yData=[1243,2315,1164,3021];
	option = {
		backgroundColor:"",
		tooltip: {
			trigger: "axis",
			transitionDuration: 0,
			backgroundColor: 'rgba(83,93,105,0.8)',
			borderColor: '#535b69',
			borderRadius: 8,
			borderWidth: 2,
			padding: [5, 10],
			formatter: function (params, ticket, callback) {
				var res = '';
				for (var i = 0, l = params.length; i < l; i++) {
					res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
				}
				return res;
			},
			axisPointer: {
				type: 'shadow',
				lineStyle: {
					// type: 'dashed',
					color: '#ffff00'
				}
			}
		},
		yAxis: {
			axisTick: {
				show: false
			},
			splitLine: {
				show: false
			},
			splitArea: {
				show: false
			},
			data: XData,
			axisLabel: {
				formatter: function(value) {
					var ret = ""; //拼接加\n返回的类目项
					var maxLength = 1; //每项显示文字个数
					var valLength = value.length; //X轴类目项的文字个数
					var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
					if (rowN > 1) //如果类目项的文字大于3,
					{
						for (var i = 0; i < rowN; i++) {
							var temp = ""; //每次截取的字符串
							var start = i * maxLength; //开始截取的位置
							var end = start + maxLength; //结束截取的位置
							//这里也可以加一个是否是最后一行的判断，但是不加也没有影响，那就不加吧
							temp = value.substring(start, end) + "\n";
							ret += temp; //凭借最终的字符串
						}
						return ret;
					} else {
						return value;
					}
				},
				interval: 0,
				fontSize: 14,
				fontWeight: 100,
				textStyle: {
					color: '#9faeb5',

				}
			},
			axisLine: {
				lineStyle: {
					color: '#4d4d4d'
				}
			},
			
		},
		xAxis: {
			axisTick: {
				show: false
			},
			splitLine: {
				show: false
			},
			splitArea: {
				show: false
			},
			
			axisLabel: {
				textStyle: {
					color: '#9faeb5',
					fontSize: 16,
				}
			},
			axisLine: {
				lineStyle: {
					color: '#4d4d4d'
				}
			}
		},
		
		
		series: [{
			name:'贴标数量',
			type:"bar",
			itemStyle: {
				normal: {
					color: {
						type: 'linear',
						x: 1,
						y: 0,
						x2: 0,
						y2: 0,
						colorStops: [{
							offset: 0,
							color: '#00d386' // 0% 处的颜色
						}, {
							offset: 1,
							color: '#0076fc' // 100% 处的颜色
						}],
						globalCoord: false // 缺省为 false
					},
					barBorderRadius: 15,
				}
			},
			 label: {
					normal: {
						show: true,
						position: "right",
						textStyle: {
							color: "#ffc72b",
							fontSize: 12
						}
					}
				},
			data: yData,
			barWidth: 16,
		},
		// {
		// 	name:'折线',
		// 	type:'line',
		// 	itemStyle : {  /*设置折线颜色*/
		// 		normal : {
		// 		   /* color:'#c4cddc'*/
		// 		}
		// 	},
		// 	data:yData
		// }
	]
	};
	myChart5.setOption(option);
}
//刷新myChart5数据

//各市场今日贴标数量ajax
function charts6Ajax() {
    $.ajax({
        type: 'GET',
        // url: `${URL}supervise/findnumByMarketToday/houseId?id=${marketId}`,
        url:`${URL}supervise/findnumByMarketToday`,
        dataType: "json",
        success: function (data) {
            charts6Data  = data.object;      
            init_myChart6(charts6Data);
        },
        error: function (data) { }
    })
}

// 各市场今日贴标数量柱状图
function init_myChart6(charts6Data){
	// 近一年日均贴标量
	var avgData = charts6Data.avgNum
	//各市场今日贴标量
	var marketToday = charts6Data.data.uploadData
	// var data = {"uploadData":[{"count":5421,"date":"7月29日"},{"count":6512,"areaName":"允书白市场"},{"count":3721,"areaName":"升平市场"},{"count":2842,"areaName":"泰丰市场"}
	// 						,{"count":6427,"areaName":"福兴市场"},{"count":4422,"areaName":"新市市场"},{"count":1020,"areaName":"建设市场"},{"count":1421,"areaName":"文田市场"},{"count":1776,"areaName":"生态市场"}
	// 						,{"count":2428,"areaName":"北区市场"}]};
	var data = {"uploadData":marketToday};		

	var uploadCnt = [];
	var areaNameS = [];
	var timeOut = 0;

	if (data.uploadData) {
		for (var i = 0; i < data.uploadData.length; i++) {
			uploadCnt.push(data.uploadData[i].count);
			areaNameS.push(data.uploadData[i].areaName);
		}
	}
	
	var option = {
		"tooltip": {
			"trigger": "axis",
			transitionDuration: 0,
			backgroundColor: 'rgba(83,93,105,0.8)',
			borderColor: '#535b69',
			borderRadius: 8,
			borderWidth: 1,
			padding: [5, 10],
			axisPointer: {
				type: 'shadow',
				lineStyle: {
					color: '#ffff00'
				}
			}
		},
		"grid": {
			"top": '40',
			"left": '30',
			"right": '10',
			"bottom": '48+',
	
			textStyle: {
				color: "#fff"
			}
		},
		"legend": {
			right: '24',
			top: "5",
			itemWidth: 8,
			itemHeight: 12,
			textStyle: {
				color: '#fff',
				fontSize:14
			},
		},
		"calculable": true,
		dataZoom: [{
			// 区域缩放组件
			// show: true,
			show:false,
			startValue: 0,
			endValue: 5,
		}],
		xAxis: [{
			'type': 'category',
			"axisTick": {
				"show": false
			},
			"axisLine": {
				"show": false,
				lineStyle: {
					color: '#868c96'
				}
			},
			"axisLabel": {
				"interval": 0,
				fontSize:14,
				formatter:function(value)
				{
					var ret = "";//拼接加\n返回的类目项
					var maxLength = 2;//每项显示文字个数
					var valLength = value.length;//X轴类目项的文字个数
					var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
					if (rowN > 1)//如果类目项的文字大于3,
					{
						for (var i = 0; i < rowN; i++) {
							var temp = "";//每次截取的字符串
							var start = i * maxLength;//开始截取的位置
							var end = start + maxLength;//结束截取的位置
							//这里也可以加一个是否是最后一行的判断，但是不加也没有影响，那就不加吧
							temp = value.substring(start, end) + "\n";
							ret += temp; //凭借最终的字符串
						}
						return ret;
					}
					else {
						return value;
					}
				}

			},
			"splitArea": {
				"show": false
			},
			'data': areaNameS,
			splitLine: {
				show: false
			}
		}],
		"yAxis": [
			{
				"type": "value",
				offset: -14,
				"splitLine": {
					"show": false
				},
				"axisLine": {
					"show": false,
					lineStyle: {
						color: '#868c96'
					}
				},
				"axisTick": {
					"show": false
				},
				"axisLabel": {
					"interval": 0,
					fontSize:14
				},
				"splitArea": {
					"show": false
				}
			}],
		
		"series": [
			{
				"name": "今日贴标量",
				"type": "bar",
				"barGap": "10%",
				itemStyle: {//图形样式
					normal: {
						"color": '#4a4df0'
					}
				},
				label: {
					normal: {
						show: true,
						position: "top",
						textStyle: {
							color: "#ffc72b",
							fontSize: 10
						}
					}
				},
				"data": uploadCnt,
				barWidth: 30,
			},{
			name:'近一年日均贴标量',
			type:'line',
			itemStyle : {  /*设置折线颜色*/
				normal : {
				  color:'#c7b198'
				}
			},
			data:avgData,
			
			"splitLine": {
				"show": false
			},
			"axisLine": {
				"show": false,
			},
			"axisTick": {
				"show": false
			},
			"axisLabel": {
				"interval": 0,
				fontSize:14
			},
			"splitArea": {
				"show": false
			}
		}
		]
	};


	//自动滚动
	function autoMove(){
		  timeOut = setInterval(()=>{
		 // clearInterval(this.timeOut)
		 // 每次向后滚动一个，最后一个从头开始。
		//  if(stopMove){ return }
		   if (Number(option.dataZoom[0].endValue) === data.uploadData.length-1) {
			  option.dataZoom[0].endValue = 5;
			  option.dataZoom[0].startValue = 0;
		 } else {
			  option.dataZoom[0].endValue =  option.dataZoom[0].endValue + 1;
			  option.dataZoom[0].startValue =  option.dataZoom[0].startValue + 1;
		 }
		 myChart6.setOption(option);
	 }, 3000);
	 }

	  //停止滚动
	  function stop(){
		// this.stopMove=true
		clearInterval(timeOut)
	  }
	
	  //继续滚动
	  function goMove(){
		//  this.stopMove=false
		 autoMove()
	  }

	// 使用刚指定的配置项和数据显示图表
	myChart6.setOption(option);
	myChart6.on('mouseover',stop);
	myChart6.on('mouseout',goMove);
	autoMove();

}

//市场贴标前十ajax
function charts7Ajax() {
    $.ajax({
        type: 'GET',
        // url: `${URL}supervise/findnumByMarketToday/houseId?id=${marketId}`,
        url:`${URL}supervise/topTenMarkets`,
        dataType: "json",
        success: function (data) {
            charts7Data  = data.object;      
            init_myChart7(charts7Data);
        },
        error: function (data) { }
    })
}


function init_myChart7(charts7Data){
	var data = charts7Data 

var colorList = [
    '#ff2600',
    '#ffc000',
    '#00ad4e',
    '#0073c2',
    '#165868',
    '#e76f00',
    '#316194',
    '#723761',
    '#00b2f1',
    '#4d6022',
    '#4b83bf',
    '#f9c813',
    '#0176c0'
];

var xData = []
var yData = []

for (var i = 0; i < data.length; i++) {
	xData.push(data[i].marketName);
	yData.push(data[i].topTen);
}

// var xData = ['汾江市场','文田市场','泰丰市场','升平市场','新市市场','福兴市场', '沙口市场', '允书白市场', '生态市场','仲恺市场'];
// var yData = [9999,8888,7777,6666,5555,4444,3333,2222,1111,123];
option = {
    color:colorList,
    "tooltip": {
			"trigger": "axis",
			transitionDuration: 0,
			backgroundColor: 'rgba(83,93,105,0.8)',
			borderColor: '#535b69',
			borderRadius: 8,
			borderWidth: 2,
			padding: [5, 10],
			formatter: function (params, ticket, callback) {
				var res = '';
				for (var i = 0, l = params.length; i < l; i++) {
					res += '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
				}
				return res;
			},
			axisPointer: {
				type: 'shadow',
				lineStyle: {
					type: 'dashed',
					color: '#ffff00'
				}
			}
		},
    toolbox: {
        show : true,
        feature : {
            mark : {
                show: true
            },

        }
    },
    grid: {
       "borderWidth": 0,
			"top": '30',
			"left": '30',
			"right": '10',
			"bottom": '50',
			textStyle: {
				color: "#fff"
			}
    },
	
    xAxis : [
       {
			'type': 'category',
			"axisTick": {
				"show": false
			},
			"axisLine": {
				"show": false,
				lineStyle: {
					color: '#868c96'
				}
			},
			"axisLabel": {
				"interval": 0,
				fontSize:14,
				formatter:function(value)
				{
					var ret = "";//拼接加\n返回的类目项
					var maxLength = 2;//每项显示文字个数
					var valLength = value.length;//X轴类目项的文字个数
					var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
					if (rowN > 1)//如果类目项的文字大于3,
					{
						for (var i = 0; i < rowN; i++) {
							var temp = "";//每次截取的字符串
							var start = i * maxLength;//开始截取的位置
							var end = start + maxLength;//结束截取的位置
							//这里也可以加一个是否是最后一行的判断，但是不加也没有影响，那就不加吧
							temp = value.substring(start, end) + "\n";
							ret += temp; //凭借最终的字符串
						}
						return ret;
					}
					else {
						return value;
					}
				}
			},
			"splitArea": {
				"show": false
			},
			'data': xData,
			splitLine: {
				show: false
			},
		
		}
    ],
    yAxis : [
      {
				"type": "value",
				offset: -14,
				"splitLine": {
					"show": false
				},
				"axisLine": {
					"show": false,
					lineStyle: {
						color: '#868c96'
					}
				},
				"axisTick": {
					"show": false
				},
				"axisLabel": {
					"interval": 0,
					fontSize:14

				},
				"splitArea": {
					"show": false
				}
			}

    ],
    series : [
        {
            name:'贴标数',
            type:'bar',
            data:yData,
            itemStyle: {
                normal: {
                    color: function(params) {
                        // build a color map as your need.
                        var colorList = [
                            '#ff2600',
                            '#ffc000',
                            '#00ad4e',
                            '#0073c2',
                            '#165868',
                            '#e76f00',
                            '#316194',
                            '#723761',
                            '#00b2f1',
                            '#4d6022',
                            '#4b83bf',
                            '#f9c813',
                            '#0176c0'
                        ];
                        return colorList[params.dataIndex]
                    },
                   
                }
            },
			 barWidth: 30,
			 label: {
					normal: {
						show: true,
						position: "top",
						textStyle: {
							color: "#ffc72b",
							fontSize: 10
						}
					}
				},
        },
		// {
		// 	name:'折线',
		// 	type:'line',
		// 	itemStyle : {  /*设置折线颜色*/
		// 		normal : {
		// 		  color:'#d3d5fd'
		// 		}
		// 	},
		// 	data:yData
		// }
     
    ]
};


// 使用刚指定的配置项和数据显示图表。
	myChart7.setOption(option);
}


//获取当前时间
function getNowFormatDate() {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var Hour =  date.getHours();       // 获取当前小时数(0-23)
    var Minute =  date.getMinutes();     // 获取当前分钟数(0-59)
    var Second = date.getSeconds();     // 获取当前秒数(0-59)
    var show_day=new Array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
    var day=date.getDay();
    if (Hour<10) {
        Hour = "0" + Hour;
    }
    if (Minute <10) {
        Minute = "0" + Minute;
    }
    if (Second <10) {
        Second = "0" + Second;
    }
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = '<div>'+'数据更新至'+year + '年' + month +'月' + strDate+'日'+Hour+'时'+'</div>';
    // var HMS = Hour + ':' + Minute +':' + Second;
	var HMS = '<div>'+  Hour + '时'+'</div>';
	var temp_time = year+'-'+month+'-'+strDate+' '+HMS;
    $('.nowTime li:nth-child(1)').html(currentdate);
    // $('.nowTime li:nth-child(2)').html(HMS);
	//$('.topRec_List li div:nth-child(3)').html(temp_time);
    setTimeout(getNowFormatDate,1000);//每隔1秒重新调用一次该函数
}


// 返回按钮
function reButt() {
	window.location.href = '/static/MarketSupAdmin.html'
}


// 选择其他镇时提示无数据
// $('.select-ul').on('click', 'li', function () {
// 	alert("该镇无相关数据");
// 	window.location.href = '/static/MarketSupData.html';
// });


// 客户贴标数据ajax
function getUsers() {
    $.ajax({
        type: "GET",
        // url: `${URL}PoultrySales/findCountOfParentThisYear/by/house?houseId=${marketId}`,
        url:`${URL}supervise/searchcustomermarketnum`,
        dataType: "json",
        success(data) {
            data = data.object.data.allData
			userData(data)
        },
        error() { }
    })
}

// 客户贴标数据
function userData(data) {
    let allUserData = ''
	for (var i = 0; i < data.length; i++) {
		allUserData += '<li>' +
			'<div>' + data[i].customerName + '</div>' +
			'<div>' + data[i].marketName + '</div>' +
			'<div>' + data[i].totalCount + '</div>' +
			'</li>'	
		$(".maquee ul").html(allUserData)
	}
}

// 客户贴标数据自动滚动
$(function () {
	setInterval('autoScroll(".maquee")', 2000);
})

function autoScroll(obj) {
	$(obj).find("ul").animate({
		marginTop: "-39px"
	}, 500, function () {
		$(this).css({ marginTop: "0px" }).find("li:first").appendTo(this);
	})
}

setInterval(function (){
    window.onresize = function () {
		this.myChart1.resize;
		this.myChart2.resize;
		this.myChart3.resize;
		this.myChart5.resize;
		this.myChart6.resize;
		this.myChart7.resize;
    }
},3600000)

/*function resize(){
	window.addEventListener("resize", () => { 
  	this.myChart1.resize;
	this.myChart2.resize;
	this.myChart3.resize;
	this.myChart5.resize;
	this.myChart6.resize;
	this.myChart7.resize;
});
}*/

//myChart7.resize();
